home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Classes / SocketClasses / SktSocket.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-23  |  6.0 KB  |  125 lines

  1. /***************************************************************************
  2. *                                                                          *
  3. * SktSocket.h                                                              *
  4. * Copyright 1992 by Nik A Gervae                                           *
  5. *                                                                          *
  6. * One of a set of three Objective-C classes (SktSocketManager, SktSocket,  *
  7. * and SktSocketUser) which implement a convenient interface to Berkeley    *
  8. * stream sockets under NeXTSTEP(r).  See the accompanying class            *
  9. * specifications (files with a .rtf or .spec suffix) for further           *
  10. * information.                                                             *
  11. *                                                                          *
  12. * NeXTSTEP is a registered trademark of NeXT Computer, Inc.                *
  13. *                                                                          *
  14. ****************************************************************************
  15. *                                                                          *
  16. * LICENSE                                                                  *
  17. *                                                                          *
  18. * This program is free software; you can redistribute it and/or modify     *
  19. * it under the terms of the GNU General Public License as published by     *
  20. * the Free Software Foundation.                                            *
  21. *                                                                          *
  22. * The program and this makefile are distributed in the hope that it will   *
  23. * be useful, but are provided "AS IS" AND WITHOUT ANY WARRANTY; without    *
  24. * any express or implied warranty of MERCHANTABILITY or FITNESS FOR A      *
  25. * PARTICULAR PURPOSE. See the GNU General Public License for more details. *
  26. * Any use or distribution of the program and documentation must include    *
  27. * appropriate copyrights to acknowledge Nik A. Gervae and the Free         *
  28. * Software Foundation, Inc.                                                *
  29. *                                                                          *
  30. * You should have received a copy of the GNU General Public License        *
  31. * along with this program; if not, write to the Free Software              *
  32. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                *
  33. *                                                                          *
  34. ****************************************************************************
  35. *                                                                          *
  36. * VERSION HISTORY                                                          *
  37. *                                                                          *
  38. * Version numbers are simply dates in the form YYYYMMDD.  These represent  *
  39. * the date that version was finished.  Only significantly changed versions *
  40. * are reported here, or those versions requiring explanation of changes.   *
  41. * There may be many interim stages between dated versions.                 *
  42. *                                                                          *
  43. * DateVersion Primary Author  Notes                                        *
  44. * ----------- --------------- -------------------------------------------- *
  45. * 19920327    Nik A Gervae    First released version                       *
  46. * 19920723    Nik A Gervae    Actually released                            *
  47. *                                                                          *
  48. ***************************************************************************/
  49.  
  50. #import <stddef.h>
  51. #ifdef NS3
  52. #import <objc/zone.h>
  53. #else
  54. #import <zone.h>
  55. #endif
  56.  
  57. #import <objc/Object.h>
  58.  
  59. #import "util.h"
  60. #import "SktSocketManager.h"
  61. #import "SktSocketUser.h"
  62.  
  63. /*
  64.  * Minimum size of the output queue.  It gets shrunk to this if
  65.  * the content of the queue gets significantly smaller than this.
  66.  * Use this to optimize your output.  If you get tons of output,
  67.  * you may want to increase this.
  68.  */
  69. #define OUTQSIZE  1024
  70.  
  71. /***************************************************************************
  72. *                                                                          *
  73. * SktSocketUser class                                                      *
  74. *                                                                          *
  75. * The instance variable user is accessed only through methods (except in   *
  76. * -init... and -free), so that you can override the behavior in subclasses *
  77. * by returning specific values.  It may sound gratuitous now, but the      *
  78. * habit *will* pay off sooner or later.                                    *
  79. *                                                                          *
  80. ***************************************************************************/
  81. @interface SktSocket : Object
  82. {
  83.   struct SktSocketManager *manager; // keeps SktSocket in sync
  84.   struct SktSocketUser    *user;    // uses SktSocket for I/O
  85.  
  86.   int       socketFd;        // file descriptor of the socket
  87.   char     *hostaddress;     // address of connected host in dot notation
  88.   char     *hostname;        // name of connected host
  89.   char     *outputQueue;     // data to be sent to connected host
  90.   long int  queueLength;     // length of the queue
  91.  
  92.   NXZone   *zone;            // zone alloc'ed from
  93. }
  94.  
  95.  
  96. // Initializing
  97. - init;  // DON'T EVER SEND THIS
  98. - initOnFd:(int)serviceSocketFd
  99.     withManager:(struct SktSocketManager *)aManager;
  100. - initOnHostname:(char *)hostname andPort:(int)port;
  101. - initOnAddress:(char *)hostAddress andPort:(int)port;
  102. - setSocketOptions:(int)fd;
  103. - close;
  104. - free;
  105.  
  106. // Access
  107. - setUser:(struct SktSocketUser *)aUser;
  108. - (struct SktSocketUser *)user;
  109. - (struct SktSocketManager *)manager;
  110.  
  111. - (int)socketFd;
  112. - (const char *)hostaddress;
  113. - (const char *)hostname;
  114.  
  115. // I/O support
  116. - readInput;
  117.  
  118. - queueOutput:(const char *)output ofLength:(long int)length;
  119. - queueOutputString:(const char *)aString;
  120.  
  121. - flushOutput;
  122. - purgeOutput;
  123.  
  124. @end /*interface SktSocket*/
  125.